package com.service;

import com.dao.OrderMapper;
import com.dao.PaymentMapper;
import com.pojo.Order;
import com.pojo.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

@Service
public class PaymentService {
    @Autowired
    PaymentMapper paymentMapper;

    @Autowired
    OrderMapper orderMapper;

    public BigDecimal pay (Payment payment) {

        Order payOrder = orderMapper.selectPQbyOid(payment.getoId());

        //支付足够
        if(payment.getpReceiptAmount().compareTo(payOrder.getoTotalMoney()) >= 0){
            payment.setpDate(new Date());
            paymentMapper.insertSelective(payment); //插入记录
            //返回余额
            return payment.getpReceiptAmount().subtract(payOrder.getoTotalMoney());
        }else{
            return null;
        }



    }

}
